package com.lwp.demo.js.translation;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegUtils {

//    String pattern = "(\\D*)(\\d+)(.*)";
//    private final static String CHINESE_PATTERN = "^[\\u4e00-\\u9fa5]{0,}$";
//    private final static String CHINESE_PATTERN = "(.*[\\u4e00-\\u9fa5]{0,}.*)+";
    private final static String CHINESE_PATTERN = "[\\u4e00-\\u9fa5]";

/*    private final static String CHINESE_SINGLE_PATTERN = "'.*[\\u4e00-\\u9fa5]+.*'";
    private final static String CHINESE_DOUBLE_PATTERN = "\".*[\\u4e00-\\u9fa5].*\"";*/

    private final static String CHINESE_SINGLE_PATTERN = "'[^\']*'";
    private final static String CHINESE_DOUBLE_PATTERN = "\"[^\\\"]*\"";
    // 创建 Pattern 对象
    public final static Pattern REG_CHINESE = Pattern.compile(CHINESE_PATTERN);
    /**
     * 匹配单引号内的中文
     */
    public final static Pattern CHINESE_SINGLE = Pattern.compile(CHINESE_SINGLE_PATTERN);
    /**
     * 匹配双引号内的中文
     */
    public final static Pattern CHINESE_DOUBLE = Pattern.compile(CHINESE_DOUBLE_PATTERN);


    /**
     * 包含中文
     * @param str
     * @return
     */
    public static boolean containChinese(String str) {
        Matcher matcher = REG_CHINESE.matcher(str);
        if (matcher.find()) {
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        String str = "\"1231231安抚呢我 完了冯矿伟\"";
        str = "23423'2341231231安抚呢我 完了冯矿伟\"'23423--- '2341231231安抚呢我 完了冯矿伟222\"'999";
//        boolean matches = CHINESE_DOUBLE_PATTERN.matches(str);
        Pattern p = Pattern.compile(CHINESE_DOUBLE_PATTERN);
        Matcher matcher = p.matcher(str);
        while (matcher.find()) {
            System.out.println(matcher.group());
        }

        Pattern p1 = Pattern.compile(CHINESE_SINGLE_PATTERN);
        Matcher matcher1 = p1.matcher(str);
        while (matcher1.find()) {
            System.out.println(matcher1.group());
        }

    }
}
